--
-- Author: shunguo.chen
-- Date: 2016-12-02 10:12:27
--
-- ShareMountPanel

local ClassRef = app.mvc.createPanelClass(...)

function ClassRef.create()
	local sprite = ClassRef.extend(ccui.Layout:create())
	sprite:setClippingEnabled(true)

	local node = cc.CSLoader:createNode(Res.ShareMountPanel, true)
	node:setPosition(display.cx, display.cy)
	node:setName("content")
	sprite:addChild(node)
	ccui.Helper:doLayout(node)

	sprite:init()
	return sprite
end

function ClassRef:init(data)
	self.super.init(self, data)

	self:setContentSize(display.size)

	self._conPanel = self:getChildByName("content")

	local children = self._conPanel:findChild("Panel_1"):getChildren()
	for i,child in ipairs(children) do
		child:setVisible(false)
	end

	self:performWithDelay(function()
			local bg = self._conPanel:findChild("Panel_2/base")
			if bg then
				bg:loadTexture("art/fenxiang/base_5.png")
			end
		end, 0)
end

function ClassRef:refresh()
	if self._data then
		local children = self._conPanel:findChild("Panel_1"):getChildren()
		-- for i,child in ipairs(children) do
		-- 	local id = tonumber(child:getName())
		-- 	if not self._data[id] then
		-- 		display.applySpriteShader(child, "ShaderDark")
		-- 	end
		-- 	child:setVisible(true)
		-- end
		local i = 0
		local function showMount()
			i = i + 1
			local child = children[i]
			if child then
				local id = tonumber(child:getName())
				if not self._data[id] then
					-- display.applySpriteShader(child, "ShaderDark")
					child:setColor(cc.c3b(50, 50, 50))
				end
				child:setVisible(true)
			else
				self:stopAction(self._action) 
				self._action = nil
			end
		end
		if self._action then 
			self:stopAction(self._action) 
			self._action = nil
		end
		self._action = self:schedule(showMount, 0)
	end
end

return ClassRef